<script src="<?php echo RESOURCE_URL?>/js/jquery.js"></script>
<form>
<table>
    <tr><td>
            <input placeholder="用户名" type="text" name="name" required>
        </td></tr>
    <tr><td><input type="password" name="pwd" placeholder="密码" required></td></tr>
    <tr><td><label>学生<input type="radio" name="role" value="0"  required></label>
            <label>老师<input type="radio" name="role" value="1"  required></label></td></tr>
    <tr><td><input type="button" value="添加"></td></tr>
</table>
</form>
<script>
    $(function(){
        $('input:button').click(function(){
            /* var arr = $('form').serializeArray();//[{name:'name',value:'zhyg'},{name:'pwd',value:'555888'}]
             $.post('index.php?act=user&op=add',{'user_name':arr[0].value,'pwd':arr[1].value,'role':arr[2].value,'add2':1},function(res){
             if(res.state){
             alert(res.msg);
             window.location.href="index.php?act=user&op=list";
             }else{
             alert(res.msg);
             window.location.reload();
             }
             },'json');*/
            //凡是收集表单数据作为传递参数时，用.ajax()方法会更简便
            var data_add = $('form').serialize();
            data_add+= '&add2=1';
            //alert(data_add);
            $.ajax({
                type:'post',
                data:data_add,
                dataType:'json',
                url:'index.php?act=user&op=add',
                success:function(res){
                    if(res.state){
                        alert(res.msg);
                        window.location.href="index.php?act=user&op=list";
                    }else{
                        alert(res.msg);
                        window.location.reload();
                    }
                }
            });
        });
    })

</script>